// 创建路由对象
import {createRouter, createWebHashHistory} from 'vue-router'
import layout from '@/views/layout/index.vue'
import home from '@/views/home/index.vue'
const router = createRouter({
  routes: [
    { 
      path: '/',
      component: layout,
      children: [
        {
          path: '', // 默认路由, 访问 / 等于先加载 layout 在加载这个组件
          component: home
        },
        {
          path: 'category/:id',
          component: () => import('@/views/category/index.vue')
        },
        {
          path: 'category/sub/:id',
          component: () => import('@/views/category/sub.vue')
        },
        {
          path: 'paly',
          component: () => import('@/views/paly/index.vue')
        },
        {
          path: 'goods/:id',
          component: () => import('@/views/goods/index.vue')
        }
      ]
     },
     { 
      path: '/login',
      component: () => import('@/views/login/index.vue')
     }
  ],
  history: createWebHashHistory(),
  scrollBehavior: () => {
    return {
      top: 0
    }
  }
})

// 导出路由对象
export default router